package org.come.model;

public class Door {
	//地图id
	private String doorid;
	//地图id [1]
	private String doormap;
	//触发矩阵
	private String doorrect;
	//坐标
	private String doorpoint;
	//传送名
	private String doorkey;
	//触发矩阵坐标
	private int[] rects;
	public String getDoorid() {
		return doorid;
	}
	public void setDoorid(String doorid) {
		this.doorid = doorid;
	}
	public String getDoormap() {
		return doormap;
	}
	public void setDoormap(String doormap) {
		this.doormap = doormap;
	}
	public String getDoorrect() {
		return doorrect;
	}
	public void setDoorrect(String doorrect) {
		this.doorrect = doorrect;
	}
	public String getDoorpoint() {
		return doorpoint;
	}
	public void setDoorpoint(String doorpoint) {
		this.doorpoint = doorpoint;
	}
	public String getDoorkey() {
		return doorkey;
	}
	public void setDoorkey(String doorkey) {
		this.doorkey = doorkey;
	}
	public int[] getRects() {
		if (rects==null&&doorrect!=null) {
			if (!"".equals(doorrect)&&!"0|0|0|0".equals(doorrect)) {
				String[] rect =doorrect.split("\\|");
				rects=new int[4];
				for (int i = 0; i < rects.length; i++) {
					rects[i] = Math.abs(Integer.parseInt(rect[i]));
				}
			}
			doorrect=null;
		}
		
		if (rects != null) {
			if (rects[1] < rects[0]) {
				int temp = rects[1];
				rects[1] = rects[0];
				rects[0] = temp;
			}
			if (rects[3] < rects[2]) {
				int temp = rects[3];
				rects[3] = rects[2];
				rects[2] = temp;
			}
		}
		
		return rects;
	}
	public void setRects(int[] rects) {
		this.rects = rects;
	}

	/**
	 * 在坐标库中绘制出一个传送矩形
	 * @return
	 */
	public void getDoor(byte[][] point){
		if (rects == null) {
			getRects();
		}
		for (int x = rects[0]/20; x < rects[1]/20 ; x++) {
			for (int y = rects[2]/20 ; y < rects[3]/20 ; y++) {
				if (point[y][x] != 0) {
					point[y][x] = 3;
				}
			}
		}
	}
}
